

import jakarta.servlet.*;
import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;

import java.io.IOException;
import java.io.PrintWriter;

@WebServlet(name = "demo.TestServlet02", urlPatterns = "/T2")
public class TestServlet02 extends HttpServlet {

    public void init(ServletConfig config) throws ServletException {
        System.out.println("int method is called");
    }

//    public void service(ServletRequest request, ServletResponse response) throws ServletException {
//        System.out.println("Hello World");
//
//    }
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException{
        this.doPost(request,response);
    }

    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException{
        // 编码
        response.setContentType("text/html;charset=UTF-8");
        // 向前台页面输出内容
        PrintWriter out = response.getWriter();
        out.print("杨经堯");
    }
    public void destroy() {
        System.out.println("destroy method is called");
    }
}
